package jnpf.service.impl;

import jnpf.entity.Whu_interviewrecordEntity;
import jnpf.mapper.Whu_interviewrecordMapper;
import jnpf.service.Whu_interviewrecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.util.RandomUtil;


import jnpf.model.whu_interviewrecord.Whu_interviewrecordPagination;
import java.util.stream.Collectors;





import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.text.SimpleDateFormat;
import jnpf.util.*;
import java.util.*;

/**
 *
 * whu_interviewrecord
 * 版本： V3.2.0
 * 版权： 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * 作者： JNPF开发平台组
 * 日期： 2025-06-30
 */
@Service

public class Whu_interviewrecordServiceImpl extends ServiceImpl<Whu_interviewrecordMapper, Whu_interviewrecordEntity> implements Whu_interviewrecordService {

    @Autowired
    private UserProvider userProvider;






    @Override
    public List<Whu_interviewrecordEntity> getList(Whu_interviewrecordPagination whu_interviewrecordPagination){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
        int total=0;
        QueryWrapper<Whu_interviewrecordEntity> whu_interviewrecordQueryWrapper=new QueryWrapper<>();
        int whu_interviewrecordNum =0;
        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getInid())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getInid,whu_interviewrecordPagination.getInid());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getScene())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getScene,whu_interviewrecordPagination.getScene());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getIntype())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getIntype,whu_interviewrecordPagination.getIntype());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getStyle())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getStyle,whu_interviewrecordPagination.getStyle());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getTodate())){
            whu_interviewrecordNum++;
            List<String> TodateList =  whu_interviewrecordPagination.getTodate();
            Long fir = Long.valueOf(TodateList.get(0));
            Long sec = Long.valueOf(TodateList.get(1));

            whu_interviewrecordQueryWrapper.lambda().ge(Whu_interviewrecordEntity::getTodate, new Date(fir))
                    .le(Whu_interviewrecordEntity::getTodate, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getType())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getType,whu_interviewrecordPagination.getType());
        }


        whu_interviewrecordQueryWrapper.lambda().eq(Whu_interviewrecordEntity::getUserid,userId);


        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getTime())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getTime,whu_interviewrecordPagination.getTime());
        }

        if(AllIdList.size()>0){
            whu_interviewrecordQueryWrapper.lambda().in(Whu_interviewrecordEntity::getId, AllIdList);
        }
        //排序
        if(StringUtil.isEmpty(whu_interviewrecordPagination.getSidx())){
            whu_interviewrecordQueryWrapper.lambda().orderByDesc(Whu_interviewrecordEntity::getId);
        }else{
            whu_interviewrecordQueryWrapper="asc".equals(whu_interviewrecordPagination.getSort().toLowerCase())?whu_interviewrecordQueryWrapper.orderByAsc(whu_interviewrecordPagination.getSidx()):whu_interviewrecordQueryWrapper.orderByDesc(whu_interviewrecordPagination.getSidx());
        }
        if((total>0 && AllIdList.size()>0) || total==0){
            Page<Whu_interviewrecordEntity> page=new Page<>(whu_interviewrecordPagination.getCurrentPage(), whu_interviewrecordPagination.getPageSize());
            IPage<Whu_interviewrecordEntity> userIPage=this.page(page, whu_interviewrecordQueryWrapper);
            return whu_interviewrecordPagination.setData(userIPage.getRecords(),userIPage.getTotal());
        }else{
            List<Whu_interviewrecordEntity> list = new ArrayList();
            return whu_interviewrecordPagination.setData(list, list.size());
        }
    }
    @Override
    public List<Whu_interviewrecordEntity> getTypeList(Whu_interviewrecordPagination whu_interviewrecordPagination,String dataType){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
        int total=0;
        QueryWrapper<Whu_interviewrecordEntity> whu_interviewrecordQueryWrapper=new QueryWrapper<>();
        int whu_interviewrecordNum =0;
        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getInid())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getInid,whu_interviewrecordPagination.getInid());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getScene())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getScene,whu_interviewrecordPagination.getScene());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getIntype())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getIntype,whu_interviewrecordPagination.getIntype());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getStyle())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getStyle,whu_interviewrecordPagination.getStyle());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getTodate())){
            whu_interviewrecordNum++;
            List<String> TodateList =  whu_interviewrecordPagination.getTodate();
            Long fir = Long.valueOf(TodateList.get(0));
            Long sec = Long.valueOf(TodateList.get(1));

            whu_interviewrecordQueryWrapper.lambda().ge(Whu_interviewrecordEntity::getTodate, new Date(fir))
                    .le(Whu_interviewrecordEntity::getTodate, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getType())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getType,whu_interviewrecordPagination.getType());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getUserid())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().eq(Whu_interviewrecordEntity::getUserid,whu_interviewrecordPagination.getUserid());
        }

        if(StringUtil.isNotEmpty(whu_interviewrecordPagination.getTime())){
            whu_interviewrecordNum++;
            whu_interviewrecordQueryWrapper.lambda().like(Whu_interviewrecordEntity::getTime,whu_interviewrecordPagination.getTime());
        }

        if(AllIdList.size()>0){
            whu_interviewrecordQueryWrapper.lambda().in(Whu_interviewrecordEntity::getId, AllIdList);
        }
        //排序
        if(StringUtil.isEmpty(whu_interviewrecordPagination.getSidx())){
            whu_interviewrecordQueryWrapper.lambda().orderByDesc(Whu_interviewrecordEntity::getId);
        }else{
            whu_interviewrecordQueryWrapper="asc".equals(whu_interviewrecordPagination.getSort().toLowerCase())?whu_interviewrecordQueryWrapper.orderByAsc(whu_interviewrecordPagination.getSidx()):whu_interviewrecordQueryWrapper.orderByDesc(whu_interviewrecordPagination.getSidx());
        }
        if("0".equals(dataType)){
            if((total>0 && AllIdList.size()>0) || total==0){
                Page<Whu_interviewrecordEntity> page=new Page<>(whu_interviewrecordPagination.getCurrentPage(), whu_interviewrecordPagination.getPageSize());
                IPage<Whu_interviewrecordEntity> userIPage=this.page(page, whu_interviewrecordQueryWrapper);
                return whu_interviewrecordPagination.setData(userIPage.getRecords(),userIPage.getTotal());
            }else{
                List<Whu_interviewrecordEntity> list = new ArrayList();
                return whu_interviewrecordPagination.setData(list, list.size());
            }
        }else{
            return this.list(whu_interviewrecordQueryWrapper);
        }
    }

    @Override
    public Whu_interviewrecordEntity getInfo(String id){
        QueryWrapper<Whu_interviewrecordEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(Whu_interviewrecordEntity::getId,id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(Whu_interviewrecordEntity entity){
        this.save(entity);
    }

    @Override
    public boolean update(String id, Whu_interviewrecordEntity entity){
        entity.setId(id);
        return this.updateById(entity);
    }
    @Override
    public void delete(Whu_interviewrecordEntity entity){
        if(entity!=null){
            this.removeById(entity.getId());
        }
    }
    //子表方法

    //列表子表数据方法

}
